package com.booksystem.controller;

import com.booksystem.common.RestResult;
import com.booksystem.dto.*;
import com.booksystem.dto.InventoryQueryDTO;
import com.booksystem.dto.ManualAdjustmentDTO;
import com.booksystem.dto.StockInfoDTO;
import com.booksystem.dto.WarningThresholdUpdateDTO;
import com.booksystem.service.InventoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *   库存管理控制器
 * </p>
 * @author 段伟豪
 */
@Slf4j
@Api("库存管理")
@RestController
@RequestMapping("/inventory")
public class InventoryController {

    @Autowired
    private InventoryService inventoryService;

    /**
     * 查询商品库存
     *
     * @param queryDTO 商品ID
     * @return RestResult结果
     */
    @RequestMapping(value = "/getStock", method = RequestMethod.GET)
    @ApiOperation("查询商品库存")
    public RestResult<StockInfoDTO> getStock(@Valid InventoryQueryDTO queryDTO) {
        return inventoryService.getStock(queryDTO);
    }

    /**
     * 设置库存预警阈值
     *
     * @param updateDTO 商品ID和预警阈值
     * @return RestResult结果
     */
    @RequestMapping(value = "/setWarningThreshold", method = RequestMethod.POST)
    @ApiOperation("设置库存预警阈值")
    public RestResult<Boolean> setWarningThreshold(@RequestBody @Valid WarningThresholdUpdateDTO updateDTO) {
        return inventoryService.setWarningThreshold(updateDTO);
    }

    /**
     * 手动调整商品库存
     *
     * @param adjustmentDTO 调整参数
     * @return RestResult结果
     */
    @RequestMapping(value = "/adjustStock", method = RequestMethod.POST)
    @ApiOperation("手动调整商品库存")
    public RestResult<Boolean> adjustStock(@RequestBody @Valid ManualAdjustmentDTO adjustmentDTO) {
        return inventoryService.adjustStock(adjustmentDTO);
    }
}